package com.api.browser.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.alibaba.fastjson.JSON;
import org.apache.log4j.Logger;

import weaver.hrm.User;
import weaver.systeminfo.SystemEnv;

import com.api.browser.bean.SearchConditionItem;
import com.api.browser.bean.SearchConditionOption;
import com.api.browser.bean.SplitTableBean;
import com.api.browser.bean.SplitTableColBean;
import com.api.browser.service.BrowserService;
import com.api.browser.util.BoolAttr;
import com.api.browser.util.ConditionFactory;
import com.api.browser.util.ConditionType;
import com.api.browser.util.MobileShowTypeAttr;
import com.api.browser.util.SplitTableUtil;
import com.cloudstore.dev.api.bean.SplitMobileDataBean;
import com.cloudstore.dev.api.bean.SplitMobileTemplateBean;

/**
 * @author Administrator
 * 自定义浏览按钮
 * 
 *
 */
public class MyCustomBrow extends BrowserService{
	public static final String JSON_CONFIG = "[    {        \"configs\": [            {                \"configs\": [                    {                        \"key\": \"lastname\"                    }                ],                \"key\": \"col1_row1\"            },            {                \"configs\": [                    {                        \"key\": \"workcode\"                    },                ],                \"key\": \"col1_row2\"            }        ],        \"key\": \"col1\"    }]";
	public Map<String, Object> getBrowserData(Map<String, Object> arg0)
			throws Exception {
		Logger log = Logger.getLogger(Logger.class);
	
		// TODO Auto-generated method stub
		List<SplitTableColBean> cols = new ArrayList<SplitTableColBean>();
		String backfields, fromSql, sqlwhere, orderby;
		backfields="id,workcode,lastname";//返回字段
		fromSql=" hrmresource ";//来源表
		sqlwhere=" 1=1 ";//where 条件
		orderby="workcode";//排序字段
		Map<String, Object> apidatas=new HashMap<String, Object>();
		
		cols.add(new SplitTableColBean("hide", "id"));
        cols.add(new SplitTableColBean("50%", SystemEnv.getHtmlLabelName(1268, user.getLanguage()), "lastname", "lastname", 1).setIsInputCol(BoolAttr.TRUE));
        cols.add(new SplitTableColBean("20%", SystemEnv.getHtmlLabelName(63, user.getLanguage()), "workcode", "workcode", 2));
        //cols.add(new SplitTableColBean("30%", SystemEnv.getHtmlLabelName(1278, user.getLanguage()), "manager", "manager",  3));
        SplitTableBean tableBean = new SplitTableBean(backfields, fromSql, sqlwhere, orderby, "id", cols);
        apidatas.putAll(SplitTableUtil.makeListDataResult(tableBean));
        tableBean.setMobileshowtype(MobileShowTypeAttr.ListView);
        try
        {
          SplitMobileTemplateBean localSplitMobileTemplateBean = new SplitMobileTemplateBean();
          localSplitMobileTemplateBean.addJsonTemplate("json", JSON.parseArray("[    {        \"configs\": [            {                \"configs\": [                    {                        \"key\": \"lastname\"                    }                ],                \"key\": \"col1_row1\"            },            {                \"configs\": [                    {                        \"key\": \"workcode\"                    },                ],                \"key\": \"col1_row2\"            }        ],        \"key\": \"col1\"    }]", SplitMobileDataBean.class));
          tableBean.createMobileTemplate(localSplitMobileTemplateBean);
        }
        catch (Exception localException)
        {
          log.error("localException--->"+localException.getMessage());
          localException.printStackTrace();
        }
        log.error("apidatasMyCustomBrow--->"+apidatas.toString());
        return apidatas;
	}
	@Override
	public Map<String, Object> getBrowserConditionInfo(Map<String, Object> arg0)
		throws Exception {
		Map<String, Object> apidatas = new HashMap<String, Object>();
		Logger log = Logger.getLogger(Logger.class);
		try{
		
	// TODO Auto-generated method stub
		
		List<SearchConditionItem> conditions = new ArrayList<SearchConditionItem>();
		//User user = (User) arg0.get("user");
		ConditionFactory conditionFactory = new ConditionFactory(this.user);
		conditions.add(conditionFactory.createCondition(ConditionType.INPUT, 1268, "lastname"));
		conditions.add(conditionFactory.createCondition(ConditionType.INPUT, 17080, "workcode"));
		//conditions.add(conditionFactory.createCondition(ConditionType.BROWSER, 63, "type"));
		//conditions.add(conditionFactory.createCondition(ConditionType.BROWSER, 602, "customerStatus", "cusstatus", 15078));

		//List<SearchConditionOption> statuOptions = new ArrayList<SearchConditionOption>();
		//statuOptions.add(new SearchConditionOption("",""));
		//statuOptions.add(new SearchConditionOption("1",SystemEnv.getHtmlLabelName(23773, user.getLanguage())));
		//statuOptions.add(new SearchConditionOption("2",SystemEnv.getHtmlLabelName(23774, user.getLanguage())));
		//conditions.add(conditionFactory.createCondition(ConditionType.SELECT, 19061, "status", statuOptions));

		apidatas.put("conditions", conditions);
		log.error("apidatas--->"+apidatas.toString());
		}catch(Exception e){
			log.error("getBrowserConditionInfo--->"+apidatas.toString());
		}
		return apidatas;
	
	}
}
